<template>
  <div class="contents">
    <PanelTitle title="供求分析" />
    <div class="mt">
      <div class="infoPanel">
        <div>
          <div class="infoTitle">今日库存</div>
          <div class="infoNums">
            <span class="infoNum">{{ statistData.storageQuantity }}</span>
            <span class="infoUnit">吨</span>
          </div>
          <div class="infoSub">
            同比 {{ statistData.storageQuantityRatio }}%
          </div>
        </div>
        <div>
          <div class="infoTitle">今日需求</div>
          <div class="infoNums">
            <span class="infoNum">{{ statistData.needQuantity }}</span>
            <span class="infoUnit">吨</span>
          </div>
          <div class="infoSub">同比 {{ statistData.needQuantityRatio }}%</div>
        </div>
      </div>

      <div ref="maps" class="maps"></div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import echarts from "@/components/echarts";
import PanelTitle from "../../component/PanelTitle.vue";
import http from "@/api/http";
import { env } from "@/utils/env";
import { fitChartSize } from "@/utils/dataUtil.js";

const maps = ref(null);
let statistData = ref({});

onMounted(async () => {
  let res = await http({
    url: env.VITE_ZHER_DATA_CENTER + "/operation/storage/need/statist",
    method: "get",
  });
  statistData.value = res.data;

  let xData = res.data.needStatistList.map((item) => {
    return item.perDate;
  });
  let needData = res.data.needStatistList.map((item) => {
    return item.quantity;
  });
  let storageData = res.data.storageStatistList.map((item) => {
    return item.quantity;
  });

  var myChart = echarts.init(maps.value);
  myChart.setOption({
    tooltip: {
      show: true,
      trigger: "axis",
    },
    grid: {
      left: "3%",
      right: "4%",
      bottom: "6%",
      top: "24%",
      containLabel: true,
    },
    legend: {
      data: ["库存", "需求"],
      top: 0,
      left: fitChartSize(10),
      icon: "circle",
      itemHeight: fitChartSize(5),
      itemWidth: fitChartSize(5),
      textStyle: {
        //图例文字的样式
        color: "#7AFFFD",
        fontSize: fitChartSize(9),
      },
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: xData, //["", "01/01", "03/01", "05/01", "06/01", "09/01", "11/01", ""]
      axisLabel: {
        textStyle: {
          color: "#7AFFFD",
          fontSize: fitChartSize(9),
        },
        // showMaxLabel: false,
        // showMinLabel: false,
      },
      axisTick: {
        show: false,
      },
      axisLine: {
        show: false,
      },
    },
    yAxis: {
      name: "单位：吨",
      nameTextStyle: {
        color: "#fff",
        fontSize: fitChartSize(9),
        padding: [0, 0, 0, fitChartSize(600)],
      },
      splitNumber: 4,
      splitLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.09)", //线条颜色
        },
      },
      type: "value",
      axisLabel: {
        textStyle: {
          color: "#7AFFFD",
          fontSize: fitChartSize(9),
        },
      },
    },
    series: [
      {
        name: "库存",
        type: "line",
        symbol: "none",
        smooth: true,
        symbolSize: function (data, param) {
          return fitChartSize(4);

          if (param.dataIndex === 0 || param.dataIndex === 7) {
            return 0;
          } else {
            return fitChartSize(4);
          }
        }, //拐点大小
        lineStyle: {
          normal: {
            width: "1", //折线粗细
            color: "rgba(127,209,119,1)",
            shadowOffsetX: fitChartSize(0), // 折线的X偏移
            shadowOffsetY: fitChartSize(2), // 折线的Y偏移
            shadowBlur: fitChartSize(10), // 折线模糊
            shadowColor: "rgba(0, 0, 0, .6)", //折线颜色
          },
        },
        itemStyle: {
          normal: {
            color: "rgba(62, 231, 188, 1)",
          },
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: "rgba(62, 231, 188, 0.4)",
            },
            {
              offset: 0.5,
              color: "rgba(62, 231, 188, 0.1)",
            },
            {
              offset: 1,
              color: "rgba(62, 231, 188, 0)",
            },
          ]),
        },
        data: storageData,
      },
      {
        name: "需求",
        type: "line",
        symbol: "none",
        smooth: true,
        symbolSize: function (data, param) {
          return fitChartSize(4);

          if (param.dataIndex === 0 || param.dataIndex === 7) {
            return 0;
          } else {
            return fitChartSize(4);
          }
        }, //拐点大小
        connectNulls: true,
        lineStyle: {
          normal: {
            width: fitChartSize(1), //折线粗细
            color: "rgba(0, 192, 255, 1)",
            shadowOffsetX: fitChartSize(0), // 折线的X偏移
            shadowOffsetY: fitChartSize(2), // 折线的Y偏移
            shadowBlur: fitChartSize(10), // 折线模糊
            shadowColor: "rgba(0, 0, 0, .6)", //折线颜色
          },
        },
        itemStyle: {
          normal: {
            color: "rgba(0, 192, 255, 1)",
          },
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: "rgba(0, 192, 255, 0.4)",
            },
            {
              offset: 0.5,
              color: "rgba(0, 192, 255, 0.1)",
            },
            {
              offset: 1,
              color: "rgba(0, 192, 255, 0)",
            },
          ]),
        },
        data: needData,
      },
    ],
  });
});
</script>


<style scoped lang="scss">
.contents {
  background: linear-gradient(
    to bottom,
    rgba(5, 79, 99),
    rgba(5, 79, 99, 0.1),
    rgba(5, 79, 99)
  );
  border-radius: vh(8);
  border: vh(1) solid rgba(6, 112, 180, 1);
  .mt {
    margin-top: vh(-40);
  }
}

.maps {
  height: vh(100);
  width: 100%;
}

.infoPanel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0 vw(15) 0;

  > div {
    box-sizing: border-box;
    width: vw(160);
    height: vh(80);
    background: rgba(9, 36, 44, 0.4);
    border: vh(1) solid #43e7ff;
    padding: 0 vw(20) 0px;
    margin: vh(6) 0;
  }
  .infoTitle {
    color: #fff;
    font-size: vh(10);
    line-height: vh(30);
  }
  .infoNums {
    line-height: vh(20);
  }
  .infoNumss {
    line-height: vh(36);
  }
  .infoNum {
    color: #adffd7;
    font-size: vh(26);
    font: SourceHanSansCN-Bold;
  }
  .infoUnit {
    color: #adffd7;
    font-size: vh(16);
    font: SourceHanSansCN-Bold;
    margin-left: vw(4);
  }
  .infoSub {
    font-weight: 400;
    font-size: vh(10);
    color: #adffd7;
    line-height: vh(20);
  }
}
</style>